package com.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pojo.Destroy;
import com.service.impl.DestroyServiceImpl;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (Destroy)表控制层
 *
 * @author makejava
 * @version 1.0
 * @since 2022-04-08 12:33:27
 */
@RestController
@RequestMapping("/destroy")
public class DestroyController {
    /**
     * 服务对象
     */
    @Resource
    private DestroyServiceImpl destroyServiceImpl;


    /**
     * 查询所有数据
     *
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAll")
    public PageInfo<Destroy> selectAll(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                       @RequestParam("navigatePages") String navigatePages) {
        int t = Integer.parseInt(navigatePages.replace("条", ""));
        PageHelper.startPage(page, t);
        List<Destroy> destroyList = destroyServiceImpl.selectAll();
        return new PageInfo<>(destroyList, t);
    }

    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/deleteById")
    public Map<String, Object> deleteById(@RequestParam("id") String id) {
        return this.destroyServiceImpl.deleteById(id);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @RequestMapping(value = "/selectById")
    public Map<String, Object> selectById(@RequestParam("id") String id) {
        return this.destroyServiceImpl.selectById(id);
    }

    /**
     * 通过主键更新单条数据
     *
     * @param destroy 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateById")
    public Map<String, Object> updateById(@RequestBody Destroy destroy) {
        return this.destroyServiceImpl.updateById(destroy);
    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param destroy 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert")
    public Map<String, Object> insert(@RequestBody Destroy destroy) {
        return this.destroyServiceImpl.insert(destroy);
    }

}